package com.itheima.service.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.itheima.dao.OrderSettingDao;
import com.itheima.pojo.MyOrderSetting;
import com.itheima.pojo.OrderSetting;
import com.itheima.service.OrderSettingService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

@Service(interfaceClass = OrderSettingService.class)
public class OrderSettingServiceImpl implements OrderSettingService {

    @Autowired
    private OrderSettingDao orderSettingDao;

    @Override
    public void add(List<OrderSetting> list1) {
        if (list1 == null || list1.size() == 0) {
            return;
        }
        for (OrderSetting orderSetting : list1) {
            long count = orderSettingDao.findByOrderSetting(orderSetting.getOrderDate());
            if(count>0){
                orderSettingDao.editByOrderDate(orderSetting);
            }else {
                orderSettingDao.add(orderSetting);
            }
        }
    }

    @Override
    public List<MyOrderSetting> getOrderSettingByMonth(String date) {
        return orderSettingDao.getOrderSettingByMonth(date);
    }
    @Override
    public void editOrderSettingByDate(OrderSetting orderSetting) {
        long countByOrderDate = orderSettingDao.findByOrderSetting(orderSetting.getOrderDate());
        if (countByOrderDate > 0) {
            orderSettingDao.editNumberByOrderDate(orderSetting);
        } else {
            orderSettingDao.add(orderSetting);
        }
    }
}
